package com.vms.control.weight;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Random;

import com.vms.control.weight.model.Weight;
import com.vms.control.weight.model.WeightTime.DayPart;

public class WeightGenerator {

	private static final int WEIGHT_VALUE_MIN = 50;
	private static final int WEIGHT_VALUE_DELTA = 25;
	private static final int DAYS_60 = 60;
	private Random random = new Random(System.currentTimeMillis());
	private Date generateDate = new Date();

	private float genWeightValue() {
		float weight = random.nextInt(WEIGHT_VALUE_DELTA) + WEIGHT_VALUE_MIN;
		weight += random.nextFloat();
		return weight;
	}
	
	private DayPart getDayPart () {
		if(random.nextInt(2) % 2 == 0)
			return DayPart.MORNING;
		else
			return DayPart.EVENING;
	}
	
	private Date genDate() {
		Calendar c = GregorianCalendar.getInstance();
		c.setTime(generateDate);
		c.add(Calendar.DAY_OF_YEAR, 1);
		return generateDate = c.getTime();
	}
	
	private List<Weight> genWeight() {
		List<Weight> list = new ArrayList<Weight>();
		
		DayPart dayPart = DayPart.MORNING;
		float weightValue = genWeightValue();
		Date date = genDate();
		list.add(new Weight(dayPart, weightValue, date));
		
		dayPart = DayPart.EVENING;
		weightValue = genWeightValue();
		list.add(new Weight(dayPart, weightValue, date));
		
		return list;
	}
	
	public List<Weight> generate(int days) {
		List<Weight> list = new ArrayList<Weight>();
		for (int i = 0; i < days; i++) {
			list.addAll(genWeight());
		}
		return list;
	}
	
	public List<Weight> generate() {
		return generate(DAYS_60);
	}
}
